<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\file\FileInput;
//use kartik\select2\Select2;
?>
<style type="text/css">
    .order-customer-form { font-size:12px; }    
    .order-customer-form .form-group { margin-bottom:5px;}
    .order-customer-form .form-control {height:28px;}
</style>

<div class="order-customer-form">
    <?php $form = ActiveForm::begin([
                                 'options' => ['enctype' => 'multipart/form-data',],
                                 'layout' => 'horizontal',
                                 'fieldConfig' => [
                                    'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                                    'horizontalCssClasses' => [
                                        'label' => 'col-sm-3',
                                        'wrapper' => 'col-sm-6',
                                        'error' => '',
                                    ],
                                 ],
                            ]); ?>

    <!-- ?= $form->field($model, 'first_name')->textInput(['maxlength' => 3]) ? -->
    <!-- ?= $form->field($model, 'last_name')->textInput(['maxlength' => 3]) ? -->
    <!-- ?= $form->field($model, 'en_first_name')->textInput(['maxlength' => true]) ? -->
    <!-- ?= $form->field($model, 'en_last_name')->textInput(['maxlength' => true]) ? -->

    <div class="form-group field-ordercustomer-first_name">
        <label class="control-label col-sm-3" for="leader-first_name">中文姓</label>
        <div class="col-sm-3">
            <input type="text" id="leader-first_name" class="form-control" name="Leader[first_name]" value="<?= $model->first_name ?>" maxlength="3">

            <div class="help-block help-block-error "></div>
        </div>
        <div class="col-sm-3">
            <input type="text" id="leader-en_first_name" class="form-control" name="Leader[en_first_name]" value="<?= $model->en_first_name ?>" >
            <div class="help-block help-block-error "></div>
        </div>
    </div>


    <div class="form-group field-ordercustomer-first_name">
        <label class="control-label col-sm-3" for="leader-last_name">中文名</label>
        <div class="col-sm-3">
            <input type="text" id="leader-last_name" class="form-control" name="Leader[last_name]" value="<?= $model->last_name ?>" maxlength="3">
            <div class="help-block help-block-error"></div>
        </div>
        <div class="col-sm-3">
            <input type="text" id="leader-en_last_name" class="form-control" name="Leader[en_last_name]" value="<?= $model->en_last_name ?>" >
            <div class="help-block help-block-error "></div>
        </div>
    </div>

    <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'gender')->inline(true)->radioList(\Yii::$app->params['gender']) ?>

    <?= $form->field($model, 'birthday')->widget(kartik\date\DatePicker::classname(),[
                                                'options' => ['placeholder' => Yii::t('app.order', 'Birthday')],
                                                'pluginOptions' => [
                                                    'format' => 'yyyy-mm-dd',
                                                    'autoclose'=>true,
                                                    'todayHighlight' => true
                                                ]
                                            ]); ?>
   <?php 
        $province_data = Yii::$app->params['area']['province_data'];
        if(!$model->isNewRecord){
        
            if(!isset($province_data[$model->native] ) && !empty($model->native)){
                $province_data += [$model->native=>$model->native];         
            }
        }
    ?>
    <?= $form->field($model, 'native')->widget(kartik\select2\Select2::classname(), [
            'data' => $province_data,
            'options' => [
                'placeholder' => Yii::t('app.order', 'Native'),
            ],
            'pluginOptions' => [
                'tags' => true,
                //'tokenSeparators' => [',', ' '],
                'maximumInputLength' => 10
            ],
        ]);
    ?>
    

    <?= $form->field($model, 'country')->widget(kartik\select2\Select2::classname(), [
            'data' => Yii::$app->params['area']['country_data'],
            'value' => '中国',
            'options' => [
                'placeholder' => Yii::t('app.order', 'Country'),
            ],
            'pluginOptions' => [
                //'tags' => true,
                //'tokenSeparators' => [',', ' '],
                'maximumInputLength' => 10
            ],
        ]);
    ?>

    <?= $form->field($model, 'passport')->textInput(['maxlength' => true]) ?>

    <?php 
        $pass_data = Yii::$app->params['area']['province_data'];
        if(!$model->isNewRecord){
            if(!isset($psss_data[$model->passport_add]) && !empty($model->passport_add)){

                $pass_data += [$model->passport_add=>$model->passport_add];         
            }
        }
    ?>
    <?= $form->field($model, 'passport_add')->widget(kartik\select2\Select2::classname(), [
            'data' => $pass_data,
            'options' => [
                'placeholder' => Yii::t('app.order', 'Passport Add'), //'multiple' => true 
            ],
            'pluginOptions' => [
                'tags' => true,
                'maximumInputLength' => 10
            ],
        ]);
    ?>

     <?= $form->field($model, 'passport_grant')->widget(kartik\date\DatePicker::classname(),[
                                                'options' => ['placeholder' => Yii::t('app.order', 'Passport Grant')],
                                                'pluginOptions' => [
                                                    'format' => 'yyyy-mm-dd',
                                                    'autoclose'=>true,
                                                    'todayHighlight' => true
                                                ]
                                            ]); ?>

    <?= $form->field($model, 'passport_date',['template'=>'{label}<div class="col-sm-6">{input}{hint}</div>{error}'])
                                                ->widget(kartik\date\DatePicker::classname(),[
                                                    'options' => ['placeholder' => Yii::t('app.order', 'Passport Date')],
                                                    'pluginOptions' => [
                                                        'format' => 'yyyy-mm-dd',
                                                        'autoclose'=>true,
                                                        'todayHighlight' => true
                                                    ]
                                                ]); ?>

    <?= $form->field($model, 'passport_type')->inline(true)->radioList(\Yii::$app->params['passport_type']) ?>

    <div style="position:relative;">
    <?= $form->field($model, 'passport_img')->label("")->widget(FileInput::classname(),
         [
            'language' => 'zh',
            'options' => ['accept' => '', 'multiple'=>false, 'value'=>$model->passport_img],
                'pluginOptions' => [
                    'showCaption' => false,
                    'showRemove' => true,
                    'showUpload' => false,
                    'browseClass' => 'btn btn-info',
                    'removeClass' => 'btn btn-danger',
                    'browseLabel' =>  '上传附件',
                    'removeLabel' =>  '删除'
             ]
         ]);
    ?>
    
    <?php if($model->passport_img){ ?>
        <div style="position:absolute;top:0px;left:50%;">
            <a href="/<?= $model->passport_img ?>" target="_blank">
            <img src="/<?= $model->passport_img ?>"  width=50 height=40 >
            </a>
        </div>
    <?php } ?>
    </div>

    <?= $form->field($model, 'remark',['template'=>'{label}<div class="col-md-6">{input}{error}</div>'])->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'status')->inline(true)->radioList(\Yii::$app->params['status']) ?>

    <hr style="margin-top:0px;margin-bottom:5px;">
    <div class="form-group text-center">
        <?= Html::submitButton($model->isNewRecord ? '添加领队' : '确认修改', ['class' =>  'btn btn-success btn-sm']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">
    $("#leader-first_name").change(function(){
        var name = $(this).val();
        $.get("/order/customer/pinyin", {name:name}, function(data){
            if(data){
                $("#leader-en_first_name").val(data);
            }
        });
    });

    $("#leader-last_name").change(function(){
        var name = $(this).val(); 
        $.get("/order/customer/pinyin", {name:name}, function(data){
            if(data){
                $("#leader-en_last_name").val(data);
            }
        });
    });

    // 护照日期自动赋值
    $("#leader-passport_grant").change(function(){
        var passport = $(this).val(); 
        $.get("/order/customer/passport", {passport:passport}, function(data){
            console.log(data);
            var val = $("#leader-passport_date").val();
            if(data && (val != data)){
                $("#leader-passport_date").val(data);
            }
        });
    });
</script>
<?php app\components\JsBlock::end() ?>

